package com.test.vo;

import lombok.Data;

@Data
public class ResponseResult<T> {
    //处理的错误码，当错误码为200时，表示处理成功，其他编码一律表示失败，不同的错误有不同的编码
    private String code;

    private String errorMsg; //错误的消息

    private T data; //如果没有错误，将正常返回的数据

    //为了方便使用，我们添加几个静态方法，用于快速的创建ResponseResult的对象
    public static <T> ResponseResult success(T data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = "200";
        responseResult.data = data;

        return responseResult;
    }

    public static <T> ResponseResult success(){
        ResponseResult responseResult = success(null);

        return responseResult;
    }

    public static <T> ResponseResult failure(String code, String errorMsg){
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = code;
        responseResult.errorMsg = errorMsg;

        return responseResult;
    }

    public static <T> ResponseResult failure(String errorMsg){
        ResponseResult responseResult = failure("500", errorMsg);

        return responseResult;
    }
}
